package adke.gui.animations;

import adke.Util;
import adke.gui.panels.LinePanel;
import adke.models.Player;
import adke.models.powerups.Powerup;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

public class ParticleAnimation extends Animation
{
    private Player owner;
    
    private int lastX, lastY, direction;
    
    public ParticleAnimation(Player owner)
    {
        this.owner = owner;
        
        lastX = -1;
        lastY = -1;
        direction = 0;
    }

    public boolean isDone()
    {
        return false;
    }

    public Rectangle nextFrame(Graphics2D g2d)
    {
        Point p = owner.getLine().getCurrentPosition();
        
        // niet transparant
        paintTransparant(g2d);
        
        // haal vorige blok weg
        g2d.fillRect(lastX, lastY, 10, 10);
        
        // niet transparant
        paintNormal(g2d);
        
        Rectangle oldpaint = new Rectangle(lastX, lastY, 10, 10);
        
        // probeer de particle rondjes te laten draaien om het middelpunt
        // van het voorste lijndeel
        int centerCorrection = owner.getLine().getLineThickness()/2;        // de current pos is de hoek
        double[] dxdy = Util.calculateNewPointDiff(direction, 15);
        lastX = (int)(p.x + dxdy[0])-centerCorrection;
        lastY = (int)(p.y + dxdy[1]);
        direction+=8;
        direction = direction%360;
        // teken nieuwe blokje
        g2d.setColor(Color.PINK);
        g2d.fillOval(lastX, lastY, 10, 10);
        
        // we moeten nu aangeven wat er gerepaint moet worden
        // maak een rect voor de nieuwe rect en doe de oude er bij
        Rectangle newpaint = new Rectangle(lastX, lastY, 10, 10);
        newpaint.union(oldpaint);
        return newpaint;
    }
}
